package com.car.loan.framework.aspectj.impl;

import com.car.loan.common.enums.LoanStatusEnum;
import com.car.loan.common.utils.StringUtils;
import com.car.loan.framework.aspectj.DataStatusSqlService;
import com.car.loan.project.xr.util.bo.business.LoanBaseInfo;
import com.car.loan.project.xr.util.enums.BusinessApostilleStatus;
import com.car.loan.project.xr.util.enums.FileAuditStatus;
import com.car.loan.project.xr.util.enums.LoanBusinessAuditStatus;
import com.car.loan.project.xr.util.enums.LoanBusinessStatus;
import com.car.loan.project.xr.util.enums.PaymentApplyStatus;
import com.car.loan.project.xr.util.enums.PaymentAuditStatus;
import com.car.loan.project.xr.util.enums.PaymentInfoStatus;
import org.springframework.stereotype.Service;

/**
 * @author huangding
 * @description 业务状态
 * @date 2019/11/9 16:07
 */
@Service
public class PaymentApplyStatusSqlServiceImpl implements DataStatusSqlService {

    @Override
    public LoanStatusEnum getLoanStatusEnum() {
        return LoanStatusEnum.PAYMENT_APPLY_STATUS;
    }

    @Override
    public LoanBaseInfo getStatusRemark(LoanBaseInfo loanBaseInfo) {
        Long paymentApplyStatus = loanBaseInfo.getPaymentApplyStatus();
        String statusRemark = StringUtils.EMPTY;
        if (PaymentApplyStatus.INIT.status == paymentApplyStatus) {
            statusRemark = "待提交";
        } else if (PaymentApplyStatus.SUBMIT.status == paymentApplyStatus) {
            statusRemark = "已提交";
        }
        loanBaseInfo.setStatusRemark(statusRemark);
        return loanBaseInfo;
    }

    @Override
    public String getSql(String statusAlias, Integer status) {
        String sql = " ({}.business_audit_status = "
            + LoanBusinessAuditStatus.PASS.status + "  or ({}.business_audit_status = "+LoanBusinessAuditStatus.APOSTILLE.status +"  and {}.business_apostille_status = "+BusinessApostilleStatus.PASS.status+" ) )and {}.payment_info_status = "
            + PaymentInfoStatus.INIT.status;
        if (status != null) {
            sql += " and {}.payment_apply_status =  " + status;
        }
        return sql.replace("{}", statusAlias);
    }


    @Override
    public String getSortSql(String statusAlias) {
        return " order by {}.business_audit_time desc".replace("{}", statusAlias);
    }
}
